package com.ydy.controller;

import com.ydy.pojo.Stu;
import com.ydy.pojo.bo.ShopCartBO;
import com.ydy.service.StuService;
import com.ydy.utils.ReturnResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(value = "购物车接口", tags = {"购物车的相关接口"})
@RequestMapping("shopcart")
public class ShopCartController {

    /**
     * 添加商品到购物车
     * @param userId 用户ID
     * @param shopCartBO 购物车信息
     * @param request
     * @param response
     * @return {@link ReturnResult 统一返回}
     */
    @ApiOperation(value = "添加商品到购物车", notes = "添加商品到购物车", httpMethod = "POST")
    @PostMapping("/add")
    public ReturnResult add(
            @RequestParam String userId,
            @RequestBody ShopCartBO shopCartBO,
            HttpServletRequest request,
            HttpServletResponse response
    ) {

        if (StringUtils.isBlank(userId)) {
            return ReturnResult.errorMsg("fuck you ");
        }

        System.out.println(shopCartBO);

        // TODO 前端用户在登录的情况下，添加商品到购物车，会同时在后端同步购物车到redis缓存

        return ReturnResult.ok();
    }

    /**
     * 从购物车删除信息
     * @param userId 用户ID
     * @param itemSpecId 商品规格ID
     * @param request
     * @param response
     * @return
     */
    @ApiOperation(value = "从购物车中删除商品", notes = "从购物车中删除商品", httpMethod = "POST")
    @PostMapping("/del")
    public ReturnResult del(
            @RequestParam String userId,
            @RequestParam String itemSpecId,
            HttpServletRequest request,
            HttpServletResponse response
    ) {

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(itemSpecId)) {
            return ReturnResult.errorMsg("参数不能为空");
        }

        // TODO 用户在页面删除购物车中的商品数据，如果此时用户已经登录，则需要同步删除后端购物车中的商品

        return ReturnResult.ok();
    }

}
